package com.yztc.orangeentertainment.ui.main.findfragment.findadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.findbean.HotSearchStarStarBean;
import com.yztc.orangeentertainment.ui.main.findfragment.findutils.CustomShapeTransformation;
import com.yztc.orangeentertainment.ui.main.subscribefragment.staritem.StarItemActivity;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/16.
 */
public class FindSearchStarInputAdapter extends RecyclerView.Adapter<FindSearchStarInputAdapter
        .StarInputViewHolder> {
    private List<HotSearchStarStarBean> list;
    private Context context;
    private boolean flag;

    public FindSearchStarInputAdapter(Context context, List<HotSearchStarStarBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public StarInputViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        StarInputViewHolder holder = new StarInputViewHolder(LayoutInflater.from(context).inflate
                (R.layout.findsearchstar_input, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(StarInputViewHolder holder, final int position) {
        Glide.with(context).load(list.get(position).getPic()).bitmapTransform(new
                CustomShapeTransformation(context, R.mipmap
                .abc_btn_switch_to_on_mtrl)).into(holder.intoIvone);
        holder.intoNameone.setText(list.get(position).getName());
        holder.intoShowone.setText(list.get(position).getDescription());

        holder.intoNeedclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, StarItemActivity.class);
                intent.putExtra("sid", list.get(position).getId() + "");
                context.startActivity(intent);
            }
        });

        holder.intoDingyueone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!flag) {
                    Toast.makeText(context, "成功订阅", Toast.LENGTH_SHORT).show();
                    flag = true;
                } else {
                    Toast.makeText(context, "取消订阅", Toast.LENGTH_SHORT).show();
                    flag = false;
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class StarInputViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.into_ivone)
        ImageView intoIvone;
        @InjectView(R.id.into_nameone)
        TextView intoNameone;
        @InjectView(R.id.into_showone)
        TextView intoShowone;
        @InjectView(R.id.into_dingyueone)
        TextView intoDingyueone;
        @InjectView(R.id.into_needclick)
        RelativeLayout intoNeedclick;

        public StarInputViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

}
